﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace FireBillBook.Core.Models
{
    public class PlatformServiceInfoCollection
    {
        public PlatformServiceInfoCollection()
        {

        }

        public PlatformServiceInfoCollection(List<PlatformServiceInfo> infos)
        {
            foreach (var info in infos)
            {
                if (!TryAdd(info))
                {
                    throw new ArgumentException($"已存在键{info.ServiceName}");
                }
            }
        }
        public Dictionary<string, PlatformServiceInfo> Value { get; set; } = new Dictionary<string, PlatformServiceInfo>();
        
        public bool TryAdd(PlatformServiceInfo info)
        {
            if (string.IsNullOrEmpty(info.ServiceName))
            {
                throw new ArgumentNullException($"服务器名称不能为空");
            }
            return Value.TryAdd(info.ServiceName, info);
        }
    }
}
